import Taro, { Component } from '@tarojs/taro'
import { Text, View } from '@tarojs/components'
import './index.scss'
import classNames from 'classnames'

interface IProps {
  info: object
}

export default class ShopInfoTwo extends Component<IProps, {}> {
  props: any

  static options = {
    addGlobalClass: true
  }

  //  拨打电话
  callPhone ({ phone }) {
    if (!phone) {
      return false
    }
    wx.makePhoneCall({
      phoneNumber: phone
    })
  }

  //  使用微信内置地图查看位置
  openMap ({ lat, lng, address, shopName }) {
    if (!lat || !lng) {
      return false
    }
    wx.openLocation({
      name: shopName,
      address,
      latitude: Number(lat),
      longitude: Number(lng)
    })
  }

  render() {
    const prefixCls = 'shop-info-two'
    const { info={}, className } = this.props
    return (<View className={classNames(prefixCls, className)}>
      <View className={`${prefixCls}-info`}>
        <View className={`${prefixCls}-info-left t-o-e`}>{info.shopName}</View>
        <View className={`${prefixCls}-info-right`}>
          <Text className={`${prefixCls}-icon bnn-icon`} onClick={this.callPhone.bind(this, info)}>&#xe60a;</Text>
          <Text className={`${prefixCls}-icon bnn-icon`} onClick={this.openMap.bind(this, info)}>&#xe656;</Text>
        </View>
      </View>
      <View className={`${prefixCls}-li`}>{info.businessTime}</View>
      <View className={`${prefixCls}-li`}>{info.address}</View>
    </View>)
  }
}
